package com.dz.reflect;

import java.lang.reflect.Field;
import java.util.Objects;

public class ReflectDemo05 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        // getDeclaredField 获取单个属性
        Class c = Cat.class;// 获取当字节码
        Object o = c.newInstance();// 通过反射创建对象
        Field field = c.getDeclaredField("name");//通过反射拿到name属性
        field.setAccessible(true);// 暴力破解private
        field.set(o, "123");// 给name属性赋值
        Object value = field.get(o);// 拿到属性对于的值
        System.out.println(value);

    }

}
